home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgfs / frmtest.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-10-22  |  7.8 KB  |  233 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
  3. Begin VB.Form frmTest 
  4.    Caption         =   "SG FileSys - Enumerating Files Sample"
  5.    ClientHeight    =   4800
  6.    ClientLeft      =   45
  7.    ClientTop       =   270
  8.    ClientWidth     =   6990
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4800
  11.    ScaleWidth      =   6990
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.ListBox lstAttributes 
  14.       Height          =   1860
  15.       ItemData        =   "frmTest.frx":0000
  16.       Left            =   60
  17.       List            =   "frmTest.frx":002B
  18.       Sorted          =   -1  'True
  19.       Style           =   1  'Checkbox
  20.       TabIndex        =   8
  21.       Top             =   1188
  22.       Width           =   1668
  23.    End
  24.    Begin VB.CommandButton cmdExit 
  25.       Caption         =   "E&xit"
  26.       Height          =   336
  27.       Left            =   108
  28.       TabIndex        =   7
  29.       Top             =   4032
  30.       Width           =   1128
  31.    End
  32.    Begin VB.CheckBox chkRecurse 
  33.       Alignment       =   1  'Right Justify
  34.       Caption         =   "Recur&se"
  35.       Height          =   264
  36.       Left            =   108
  37.       TabIndex        =   4
  38.       Top             =   576
  39.       Width           =   984
  40.    End
  41.    Begin VB.CommandButton cmdEnum 
  42.       Caption         =   "Enumerate"
  43.       Default         =   -1  'True
  44.       Height          =   336
  45.       Left            =   108
  46.       TabIndex        =   5
  47.       Top             =   3564
  48.       Width           =   1128
  49.    End
  50.    Begin VB.TextBox txtMask 
  51.       Height          =   300
  52.       Left            =   936
  53.       TabIndex        =   3
  54.       Text            =   "*.*"
  55.       Top             =   144
  56.       Width           =   768
  57.    End
  58.    Begin VB.TextBox txtRoot 
  59.       Height          =   300
  60.       Left            =   2376
  61.       TabIndex        =   1
  62.       Text            =   "c:\"
  63.       Top             =   144
  64.       Width           =   4476
  65.    End
  66.    Begin ComctlLib.ListView lvItems 
  67.       Height          =   3648
  68.       Left            =   1872
  69.       TabIndex        =   6
  70.       Top             =   576
  71.       Width           =   4476
  72.       _ExtentX        =   7885
  73.       _ExtentY        =   6456
  74.       View            =   3
  75.       LabelEdit       =   1
  76.       LabelWrap       =   -1  'True
  77.       HideSelection   =   -1  'True
  78.       _Version        =   327682
  79.       ForeColor       =   -2147483640
  80.       BackColor       =   -2147483643
  81.       BorderStyle     =   1
  82.       Appearance      =   1
  83.       NumItems        =   0
  84.    End
  85.    Begin VB.Label Label3 
  86.       Caption         =   "Attributes:"
  87.       Height          =   228
  88.       Left            =   108
  89.       TabIndex        =   9
  90.       Top             =   936
  91.       Width           =   1308
  92.    End
  93.    Begin ComctlLib.ImageList imlSmallIcons 
  94.       Left            =   1368
  95.       Top             =   4068
  96.       _ExtentX        =   794
  97.       _ExtentY        =   794
  98.       BackColor       =   -2147483643
  99.       MaskColor       =   12632256
  100.       _Version        =   327682
  101.    End
  102.    Begin VB.Label Label2 
  103.       Caption         =   "File &Mask:"
  104.       Height          =   228
  105.       Left            =   108
  106.       TabIndex        =   2
  107.       Top             =   180
  108.       Width           =   804
  109.    End
  110.    Begin VB.Label Label1 
  111.       Caption         =   "&Root:"
  112.       Height          =   228
  113.       Left            =   1908
  114.       TabIndex        =   0
  115.       Top             =   180
  116.       Width           =   444
  117.    End
  118. Attribute VB_Name = "frmTest"
  119. Attribute VB_GlobalNameSpace = False
  120. Attribute VB_Creatable = False
  121. Attribute VB_PredeclaredId = True
  122. Attribute VB_Exposed = False
  123.    Option Explicit
  124. Private Sub cmdEnum_Click()
  125.    Dim oEnum As New SGFileSys.Enumerator
  126.    ' Clear list view
  127.    lvItems.ListItems.Clear
  128.    Set lvItems.SmallIcons = Nothing
  129.    imlSmallIcons.ListImages.Clear
  130.    ' Set enumerator starting point and mask
  131.    oEnum.NameMask = txtMask.Text
  132.    oEnum.RootPath = txtRoot
  133.    oEnum.Recurse = chkRecurse.Value
  134.    oEnum.AttributeMask = GetSelectedAttributes
  135.    Dim i&
  136.    Dim viewItem As ListItem, smallIcon As StdPicture
  137.    Dim fileItem As SGFileSys.Item
  138.    i = 1
  139.    ' Enumerate files
  140.    On Error Resume Next
  141.    For Each fileItem In oEnum.Items
  142.       ' Limit to 500 files
  143.       If (i > 500) Then Exit Sub
  144.       
  145.       ' Add item to the list view
  146.       Set viewItem = lvItems.ListItems.Add(, , fileItem.Name)
  147.       viewItem.SubItems(1) = fileItem.Drive & fileItem.Dir
  148.       viewItem.SubItems(2) = fileItem.TypeName
  149.       
  150.       ' Add icon to the list view item
  151.       'Set smallIcon = fileItem.Icon(sgSmall_16x16)
  152.       If Not smallIcon Is Nothing Then
  153.          imlSmallIcons.ListImages.Add i, , smallIcon
  154.          If i < 2 Then lvItems.SmallIcons = imlSmallIcons
  155.          viewItem.smallIcon = i
  156.          i = i + 1
  157.       End If
  158.    Next
  159. End Sub
  160. Private Sub cmdExit_Click()
  161.    Unload Me
  162. End Sub
  163. Private Sub Form_Load()
  164.    ' Initialize list view
  165.    lvItems.ColumnHeaders.Add 1, , "File Name", 1600
  166.    lvItems.ColumnHeaders.Add 2, , "File Path", 1600
  167.    lvItems.ColumnHeaders.Add 3, , "Type", 1600
  168.    imlSmallIcons.ListImages.Clear
  169.    ' Default attribute mask is sgfAll
  170.    lstAttributes.Selected(0) = True
  171. End Sub
  172. Private Sub Form_Resize()
  173.    Dim nBorder&, nRight&
  174.    If Me.Width < 4000 Or Me.Height < 4000 Then Exit Sub
  175.    nBorder = 100
  176.    ' Update item list position
  177.    'lvItems.Left = nBorder
  178.    lvItems.Width = Me.ScaleWidth - lvItems.Left - nBorder
  179.    lvItems.Height = Me.ScaleHeight - lvItems.Top - nBorder
  180.    ' Update button positions
  181.    nRight = lvItems.Left + lvItems.Width
  182.    cmdExit.Top = Me.ScaleHeight - cmdExit.Height - nBorder
  183.    cmdEnum.Top = cmdExit.Top - cmdEnum.Height - nBorder
  184.    ' Edit boxes
  185.    txtRoot.Width = nRight - txtRoot.Left
  186. End Sub
  187. Private Sub lvItems_DblClick()
  188.    ' Open subdirectory
  189.    If Not lvItems.SelectedItem Is Nothing Then
  190.       If Right(txtRoot.Text, 1) <> "\" And _
  191.          Right(txtRoot.Text, 1) <> "/" Then _
  192.             txtRoot.Text = txtRoot.Text & "\"
  193.       txtRoot.Text = txtRoot.Text & lvItems.SelectedItem.Text & "\"
  194.       cmdEnum_Click
  195.    End If
  196. End Sub
  197. Private Function GetSelectedAttributes()
  198.    Dim i&
  199.    GetSelectedAttributes = 0
  200.    For i = 0 To lstAttributes.ListCount - 1
  201.       If lstAttributes.Selected(i) Then
  202.          Select Case lstAttributes.List(i)
  203.             Case "sgfAll"
  204.                GetSelectedAttributes = GetSelectedAttributes + sgfAll
  205.             Case "sgfArchive"
  206.                GetSelectedAttributes = GetSelectedAttributes + sgfArchive
  207.             Case "sgfCompressed"
  208.                GetSelectedAttributes = GetSelectedAttributes + sgfCompressed
  209.             Case "sgfDirectory"
  210.                GetSelectedAttributes = GetSelectedAttributes + sgfDirectory
  211.             Case "sgfEncrypted"
  212.                GetSelectedAttributes = GetSelectedAttributes + sgfEncrypted
  213.             Case "sgfHidden"
  214.                GetSelectedAttributes = GetSelectedAttributes + sgfHidden
  215.             Case "sgfNormal"
  216.                GetSelectedAttributes = GetSelectedAttributes + sgfNormal
  217.             Case "sgfOffline"
  218.                GetSelectedAttributes = GetSelectedAttributes + sgfOffline
  219.             Case "sgfReadOnly"
  220.                GetSelectedAttributes = GetSelectedAttributes + sgfReadOnly
  221.             Case "sgfReparsePoint"
  222.                GetSelectedAttributes = GetSelectedAttributes + sgfReparsePoint
  223.             Case "sgfSparseFile"
  224.                GetSelectedAttributes = GetSelectedAttributes + sgfSparseFile
  225.             Case "sgfSystem"
  226.                GetSelectedAttributes = GetSelectedAttributes + sgfSystem
  227.             Case "sgfTemporary"
  228.                GetSelectedAttributes = GetSelectedAttributes + sgfTemporary
  229.          End Select
  230.       End If
  231.    Next
  232. End Function
  233.